import { Service } from 'egg';

export default class News extends Service {
  public async getnewsList() {
    const list = [ '111', '2222' ];
    return list;
  }

  public async getData() {
    const { ctx, config } = this;
    const url = config.api + 'appapi.php?a=getPortalList&catid=20&page=1';
    const res = await ctx.curl(url);

    return JSON.parse(res.data.toString()).result;
  }

  // 拼接链接
  public async joinHref(list: Array<object>) {
    list.map((item: any, index: number) => {
      item.href = '/newscontent?aid=' + item.aid;
      return index;
    });
    return list;
  }

  // 获取新闻详情
  public async getNewsContent(aid: string) {
    const { ctx, config } = this;
    const url = config.api + `appapi.php?a=getPortalArticle&aid=${aid}`;
    const res = await ctx.curl(url);
    return JSON.parse(res.data.toString()).result[0];
  }
}
